<?php
// Library File
include 'lib/library.php';

$profile_id = mysql_real_escape_string($_GET['id']);

		/*
		**   G E T    V A R S
		*/
		$query = mysql_query("SELECT * FROM users WHERE user_id='$profile_id'");
		$id_exists = mysql_num_rows($query);
		
		if((isset($profile_id) && !$id_exists) || !isset($profile_id)){
			refresh('/index.php');
			exit;
		}else{
			$user_array = mysql_fetch_assoc($query);
		}
		
		$query = mysql_query("SELECT * FROM profiles where user_id='$profile_id'");
		$profile_array = mysql_fetch_assoc($query);
		$keys = array_keys($profile_array);

		$title = "{$user_array['name']}'s Profile";
		$subtitle = $title;
		
		if($id_exists){
			/*
			**    C R E A T E   A N
			**      I M A G E    T H A T
			**        R E P R E S E N T S    T H E
			**          E M A I L    A D D R E S S
			*/
			
			// Create the image
			$im = imagecreate(strlen($user_array['email'])*9, 15);
			
			// Create some colors
			$bg = imagecolorallocate($im, 255, 255, 255);
			$bg = imagecolortransparent($im,$bg);
			$black = imagecolorallocate($im, 0, 0, 0);
			
			putenv('GD_FONTPATH=' . realpath('.')); 
			
			// Add the text
			// File size is about 6kb bigger for imagetfftext
			imagettftext($im, 10, 0, 5, 11, $black, 'fonts/angltrr.ttf', "{$user_array['email']}");
			
			//imagestring($im,3,0,0,"{$user_array['email']}",$black);
			//imageinterlace($im);
			imagepng($im, 'images/'.$m_user_id.$profile_id.'.png',0);
			imagedestroy($im);
		
			$content .= '
				<ul class="profile">
			';
			
			$size = count($profile_array);
			for($x=2;$x<$size;$x++){
				$key = $keys[$x];
				$name = ucwords(str_replace('_', ' ', $key));
				
				switch($key){
					case 'member_type':
						$user_array[$key] = member_type($user_array[$key]);
						break;
					case 'email':
						$user_array[$key] = '<img src="'.$addr.'/images/'.$m_user_id.$profile_id.'.png" title="Emails are images to protect you from spam" />';
						break;
				}
				
				if(!empty($user_array[$key]) && $profile_array[$key]){
					// Input
					$content .='
						<li>
						<h1 class="nice">'.$name.':</h1> <P>'.$user_array[$key].'</P>
						</li>
					';
				}
			}
				$content .= '</ul>';
			
				/*
				**   P R O F I L E
				**      S E S S I O N
				*/
				session_name("Profile");
				session_start();
				$_SESSION['p_img'] = $rel_addr.'/images/'.$m_user_id.$profile_id.'.png';
				$_SESSION['p_on_profile'] = true;
				$_SESSION['p_profile_id'] = $profile_id;
		
		}
		
		if($profile_id == $_SESSION['m_user_id']){
			$side .= '<a href="'.$addr.'/editaccount.php?mode=profile">Edit Profile</a>';
		}

/*
**   P U T    V A R S
**    O N    P A G E
*/
	head($title,$style,$scripts);
	body($header,$personal,$subtitle,$content,$navigation,$side);
	foot($footer,$dbc);
?>
